package com.example.dormitory.service;


import com.example.dormitory.entity.*;
import com.example.dormitory.mapper.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class FloorService {

    @Autowired
    private FloorMapper floorMapper;

    public int create(Floor floor) {
        return floorMapper.create(floor);
    }

    public int delete(String ids) {
        String[] arr = ids.split(",");
        int row = 0;
        for (String s : arr) {
            if(!StringUtils.isEmpty(s)){
                floorMapper.delete(Integer.parseInt(s));
            row++;
            }
        }
        return row;
    }

    public int delete(Integer id) {
        return floorMapper.delete(id);
    }

    public int update(Floor floor) {
        return floorMapper.update(floor);
    }

    public int updateSelective(Floor floor) {
        return floorMapper.updateSelective(floor);
    }

    public PageInfo<Floor> query(Floor floor) {
        if(floor != null && floor.getPage() != null){
            PageHelper.startPage(floor.getPage(),floor.getLimit());
        }
        return new PageInfo<Floor>(floorMapper.query(floor));
    }

    public Floor detail(Integer id) {
        return floorMapper.detail(id);
    }

    public int count(Floor floor) {
        return floorMapper.count(floor);
    }
}
